import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *

class Form(QDialog):
    def __init__(self,parent=None):
        super(Form,self).__init__(parent)
        layout=QVBoxLayout()
        self.btn1=QPushButton("Button1")
        self.btn1.setCheckable(True)
        self.btn1.toggle()#按钮直接可以切换
        self.btn1.clicked.connect(lambda:self.whichbtn(self.btn1))
        self.btn1.clicked.connect(self.btnstate)
        self.btn2=QPushButton('image')
        self.btn2.setIcon(QIcon(QPixmap("panda.jpg")))

        self.btn3 = QPushButton("Disabled")
        self.btn3.setEnabled(False)
        self.btn4 = QPushButton("&Download")
        self.btn4.setDefault(True)
        self.btn4.clicked.connect(lambda:self.whichbtn(self.btn4))

        layout.addWidget(self.btn4)

        layout.addWidget(self.btn3)
        layout.addWidget(self.btn2)
        layout.addWidget(self.btn1)
        self.setLayout(layout)
    def btnstate(self):
        if self.btn1.isChecked():
            print("pressed")
        else:
            print("released")
    def whichbtn(self,btn):
        print("clicked button is"+btn.text())

if __name__ == '__main__':
    app=QApplication(sys.argv)
    win=Form()
    win.show()
    sys.exit(app.exec_())